package com.xcw.bos.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.xcw.bos.crm.Customer;
import com.xcw.bos.crm.CustomerService;
import com.xcw.bos.domain.DecidedZone;
import com.xcw.bos.web.action.base.BaseAction;
/**
 * 定区管理Action
 * @author xcw
 *
 */
@Controller
@Scope("prototype")
public class DecideZoneAction extends BaseAction<DecidedZone> {
    //接收分区id数组
	private String[] subareaid;
	//添加定区
	public String save(){
		decidedZoneService.save(model, subareaid);
		return "decidedZoneList";
	}
	//分页查询
	public String pageQuery(){
		decidedZoneService.pageQuery(pageBean);
		String[] excudes = new String[]{"subareas","decidedZones"};
		this.writePageBean2Json(excudes, pageBean);
		return NONE;
	}
	
	//注入代理对象，用于调用crm服务
	@Resource
	private CustomerService customerService;
	
	//查询未关联到定区的客户
	public String findnoassciationcustomer(){
		List<Customer> list = customerService.findnoassociationCustomers();
		String[] excudes = new String[]{"address"};
		this.writeList2Json(excudes, list);
		return NONE;
	}
	
	//查询已经关联到指定定区的客户
	public String findassciationcustomer(){
		List<Customer> list = customerService.findhasassociationCustomers(model.getId());
		String[] excudes = new String[]{"address"};
		this.writeList2Json(excudes, list);
		return NONE;
	}
	
	
	
	private Integer[] customerIds;//属性驱动，客户id
	
	//将客户关联到指定的定区
	public String assigncustomerstodecidedzone(){
		customerService.assignCustomersToDecidedZone(customerIds, model.getId());
		return "decidedZoneList";
		
	}
	public void setSubareaid(String[] subareaid){
		this.subareaid = subareaid;
	}
	
	public void setCustomerIds(Integer[] customerIds){
		this.customerIds = customerIds;
	}
}
